package com.spzx.product.api.fallback;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.ProductSkuFeignClient;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuPrice;
import com.spzx.product.api.domain.SkuQuery;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductSkuFeignClientFallbackFactory
 * @Author 波
 * @Date 2024/8/4 11:16
 */
@Slf4j
public class ProductSkuFeignClientFallbackFactory implements FallbackFactory<ProductSkuFeignClient> {
    @Override
    public ProductSkuFeignClient create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());
        return new ProductSkuFeignClient() {
            @Override
            public R<List<ProductSku>> getTopSale(String source) {
                return R.fail("获取畅销商品失败:" + cause.getMessage());
            }

            @Override
            public R<TableDataInfo> skuList(Integer pageNum, Integer pageSize, SkuQuery skuQuery, String source) {
                return R.fail("获取商品列表失败:" + cause.getMessage());
            }

            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                return R.fail("获取商品Sku信息失败:" + cause.getMessage());
            }

            @Override
            public R<SkuPrice> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品价格信息失败:" + cause.getMessage());
            }

            @Override
            public R<Map<String, Long>> getSkuSpecValueMap(Long pid, String source) {
                return R.fail("获取商品SkuSpecValueMap信息失败:" + cause.getMessage());
            }

            @Override
            public R<List<SkuPrice>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("获取商品SkuPriceList信息失败:" + cause.getMessage());

            }

        };
    }
}
